//
//  ApplyAuthBookCollectionViewCell.swift
//  Venus
//
//  Created by qurongxiang on 2018/8/5.
//  Copyright © 2018年 zhaowang. All rights reserved.
//

import UIKit

protocol  ApplyAuthBookCollectionViewCellDelegate : class {
    func clickAuthBookDelBtn(index:Int)
}



class ApplyAuthBookCollectionViewCell: UICollectionViewCell {
    weak var delegate: ApplyAuthBookCollectionViewCellDelegate?
    fileprivate lazy var imgView = UIImageView()
    fileprivate lazy var addImgView = UIImageView()
    fileprivate lazy var delBtn = UIButton(type:.custom)
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

extension ApplyAuthBookCollectionViewCell {
    
    @objc func clickDelBtn(btn:UIButton) {
        delegate?.clickAuthBookDelBtn(index: btn.tag)
    }
    
    func config(model:ApplyModel , index:IndexPath) {
        
        delBtn.tag = index.item
        
        if index.item == model.bookArr.count - 1 { //最后一个
            delBtn.isHidden = true
            imgView.isHidden = true
            addImgView.isHidden = false
            
        }else {
            delBtn.isHidden = false
            imgView.isHidden = false
            addImgView.isHidden = true
         
         }
        
        imgView.showImageS(model.bookArr[index.item])
    }
}

extension ApplyAuthBookCollectionViewCell {
    func setupUI() {
        contentView.backgroundColor = kColorC2
        contentView.fastCornerRadius(value: 4)
        contentView.addSubview(imgView)
        contentView.addSubview(addImgView)
        contentView.addSubview(delBtn)
        
        imgView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        
        imgView.fastCornerRadius(value: 4)
        
        
        addImgView.snp.makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 30, height: 30))
            make.center.equalToSuperview()
        }
        addImgView.image = UIImage(named: "applyAdd")
        
        
        delBtn.snp.makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 30, height: 30))
            make.top.equalToSuperview().offset(0)
            make.right.equalToSuperview().inset(0)
        }
        delBtn.setImage(UIImage(named: "icon_29"), for: .normal)
        delBtn.addTarget(self, action:#selector(clickDelBtn(btn:)) , for: .touchUpInside)
    }
}
